//
//  PersonalUserPhotoCell.m
//  ChatForHot
//
//  Created by wr on 2018/10/11.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalUserPhotoCell.h"

@interface PersonalUserPhotoCell ()

@property (nonatomic, strong) UIImageView *HOTCHATphotoImgView;
@property (nonatomic, strong) UIImageView *HOTCHATbImgView;
@property (nonatomic, strong) UIImageView *HOTCHATroundImgView;
@end

@implementation PersonalUserPhotoCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 5;
    
    self.HOTCHATphotoImgView = [[UIImageView alloc] init];
    self.HOTCHATphotoImgView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.HOTCHATphotoImgView];
    
    self.HOTCHATbImgView = [[UIImageView alloc] init];
    self.HOTCHATbImgView.image = [UIImage imageNamed:@"photo_selfback_imag"];
    self.HOTCHATbImgView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.HOTCHATbImgView];
    
    self.HOTCHATroundImgView = [[UIImageView alloc] init];
    self.HOTCHATroundImgView.image = [UIImage imageNamed:@""];
    [self addSubview:self.HOTCHATroundImgView];
    
    @weakify(self);
    [RACObserve(self, model.isSelected) subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        if (self.model.isSelected) {
            self.HOTCHATroundImgView.image = [UIImage imageNamed:@"photo_del_select"];
        }else{
            self.HOTCHATroundImgView.image = [UIImage imageNamed:@"photo_selnormall"];
        }
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.HOTCHATphotoImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.HOTCHATbImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.HOTCHATroundImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(20);
        make.right.equalTo(self).offset(-9);
        make.top.equalTo(self).offset(9);
    }];
}

- (void)setModel:(PersonalUserPhotoModel *)model{
    _model = model;
    [self.HOTCHATphotoImgView simple_setImageWithURL:[model.picAddress HOTCHATTotalStringUrl] placeholderImage:[UIImage imageNamed:@"photo_placeholder"]];
}

- (void)setIsEditMode:(BOOL)isEditMode{
    _isEditMode = isEditMode;
    if (isEditMode) {
        self.HOTCHATbImgView.hidden = NO;
        self.HOTCHATroundImgView.hidden = NO;
    }else{
        self.HOTCHATbImgView.hidden = YES;
        self.HOTCHATroundImgView.hidden = YES;
    }
}

@end

